package com.huitu.whht.api.core.common.mybatis;

import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.wrapper.ObjectWrapper;
import org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory;

import java.util.Map;

/**
 * 说明:
 * 1. 在resultType=java.util.Map 时,将key按驼峰命名进行转换
 * 2. Map中的Clob字段转换为字符串,以防转json时出错
 * 3. Map中的Date/LocalDateTime字段转换为字符串,简化SQL. 转换格式 yyyy-MM-dd HH:mm:ss
 * 用法:mybatis配置文件中,加入 'objectWrapperFactory type="com.huitu.whht.framework.common.mybatis.MapWrapperFactory"/>'
 *
 * @author ZhangAY
 * @date 2018-04-27
 */
public class MapWrapperFactory implements ObjectWrapperFactory {
    @Override
    public boolean hasWrapperFor(Object object) {
        return object instanceof Map;
    }

    @Override
    public ObjectWrapper getWrapperFor(MetaObject metaObject, Object object) {
        return new MyMapWrapper(metaObject, (Map) object);
    }
}
